package com.hh.dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.hh.jdbc.JDBCDemo;

public class NurseDAO {
	
	public JSONArray getNurses(String rylx,String ksdm){
		Connection con = null;
        PreparedStatement statement = null;
        ResultSet res = null;
        JSONArray array = new JSONArray();
        try {
            Class.forName(JDBCDemo.cfn);
            con = DriverManager.getConnection(JDBCDemo.url,JDBCDemo.user,JDBCDemo.password);
            String sql = " SELECT WH_KFYS.YGDM,XM FROM HL_BQHL,WH_KFYS "
            		+ "WHERE  HL_BQHL.YGDM=WH_KFYS.YGDM AND WH_KFYS.zlslx=? AND BQBM=? ";
            statement = con.prepareStatement(sql);
            statement.setString(1, rylx);
            statement.setString(2, ksdm);
            res = statement.executeQuery();
            while(res.next()){
            	JSONObject object = new JSONObject();
            	object.put("xm", res.getString("XM").trim());
            	object.put("ygdm", res.getString("YGDM").trim());
            	array.add(object);
            }
        } catch (Exception e) {
            // TODO: handle exception
            e.printStackTrace();
        }finally{
            try {
                if(res != null) res.close();
                if(statement != null) statement.close();
                if(con != null) con.close();
            } catch (Exception e2) {
                // TODO: handle exception
                e2.printStackTrace();
            }
        }
        return array;
	}
	
	public JSONArray getDepts(String ygdm){
		Connection con = null;
        PreparedStatement statement = null;
        ResultSet res = null;
        JSONArray array = new JSONArray();
        try {
            Class.forName(JDBCDemo.cfn);
            con = DriverManager.getConnection(JDBCDemo.url,JDBCDemo.user,JDBCDemo.password);
            String sql = " SELECT KSDM,KSMC FROM GY_YGKS,GY_ZLSKS_DZ WHERE GY_ZLSKS_DZ.KSBM=GY_YGKS.KSDM AND LX=3 AND YGDM='"+ygdm+"' ";
           
            statement = con.prepareStatement(sql);
            res = statement.executeQuery();
            while(res.next()){
            	JSONObject object = new JSONObject();
            	object.put("ksdm", res.getString("KSDM").trim());
            	object.put("ksmc", res.getString("KSMC").trim());
            	array.add(object);
            }
        } catch (Exception e) {
            // TODO: handle exception
            e.printStackTrace();
        }finally{
            try {
                if(res != null) res.close();
                if(statement != null) statement.close();
                if(con != null) con.close();
            } catch (Exception e2) {
                // TODO: handle exception
                e2.printStackTrace();
            }
        }
        return array;
	}
}
